import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";

import { Book, BookContactMap, BookContactMapGateway, BookDefaultGateway, BookMap, BookMapGateway } from "qqlx-core";
import { BookSchema, BookMapSchema, BookContactMapSchema } from "qqlx-cdk";

import { PgDaoBigId } from "../../lib/dao.pg.id-big";
import { PgDao } from "../../lib/dao.pg.id";

@Injectable()
export class BookDao extends PgDaoBigId<Book> {
  constructor(
    @InjectRepository(BookSchema)
    readonly repo: Repository<Book>,
  ) {
    super({
      repository: repo,
      relations_name: BookDefaultGateway.relations,
    });
  }
}

@Injectable()
export class BookMapDao extends PgDaoBigId<BookMap> {
  constructor(
    @InjectRepository(BookMapSchema)
    readonly repo: Repository<BookMap>,
  ) {
    super({
      repository: repo,
      relations_name: BookMapGateway.relations,
    });
  }
}

@Injectable()
export class BookContactMapDao extends PgDao<BookContactMap> {
  constructor(
    @InjectRepository(BookContactMapSchema)
    readonly repo: Repository<BookContactMap>,
  ) {
    super({
      repository: repo,
      relations_name: BookContactMapGateway.relations,
    });
  }
}
